using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITS.Core.Domain.News;
using ITS.DAL.News;
using ITS.Factory;

namespace ITS.Services.News
{
    public class NewsTagService : INewsTagService
    {
        private readonly INewsTagRepository _newsTagRepository;

        #region constructors
        public NewsTagService()
        {
            _newsTagRepository = NinjectRepositoriesFactory.Get<INewsTagRepository>();
        }
        #endregion

        #region INewsTagService Members

        public void UpdateNewsTagTotals(NewsTag tag)
        {
            if (tag == null)
                throw new ArgumentNullException("Update null tag");

            int newTotal = tag.NewsItems.Count;

            if (newTotal > 0)
            {
                tag.NewsCount = newTotal;
                _newsTagRepository.Update(tag);
            }
            else
            {
                _newsTagRepository.Delete(tag);
            }
        }

        public void InsertNewsTag(NewsTag tag)
        {
            if (tag == null)
                throw new ArgumentNullException("Insert null tag");

            _newsTagRepository.Insert(tag);
        }

        public NewsTag GetNewsTagByName(string Name)
        {
            return _newsTagRepository.GetNewsTagByName(Name);
        }

        public IList<NewsTag> GetAllNewsTag()
        {
            return _newsTagRepository.GetAllNewsTags();
        }

        public NewsTag GetNewsTagByID(int TagID)
        {
            return _newsTagRepository.GetNewsTagByTagID(TagID);
        }

        public void DeleteNewsTag(NewsTag tag)
        {
            if (tag == null)
                throw new ArgumentNullException("Delete null tag");

            _newsTagRepository.Delete(tag);
        }

        public void UpdateNewsTag(NewsTag tag)
        {
            if (tag == null)
                throw new ArgumentNullException("Update null tag");

            _newsTagRepository.Update(tag);
        }

        #endregion
    }
}
